package com.zouma.service;

import com.zouma.pojo.Cntrparty;
import jxl.Sheet;
import jxl.Workbook;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: serein
 * @DateTime: 2021/7/6 21:11
 * @Description:
 */
public class CntrpartyService {

    /**
     * 查询指定目录中电子表格中所有的数据
     * @param file 文件完整路径
     * @return
     */
    public static List<Cntrparty> getAllByExcel(String file){
        List<Cntrparty> list=new ArrayList<Cntrparty>();
        try {
            Workbook rwb=Workbook.getWorkbook(new File(file));
            Sheet rs=rwb.getSheet(0);//或者rwb.getSheet(0)
            int clos=rs.getColumns();//得到所有的列
            int rows=rs.getRows();//得到所有的行

            System.out.println(clos+" rows:"+rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {
                    //第一个是列数，第二个是行数
                    String cntrpartyType=rs.getCell(j++, i).getContents();//默认最左边编号也算一列 所以这里得j++
                    String cntrpartyCode=rs.getCell(j++, i).getContents();
                    String cntrpartyName=rs.getCell(j++, i).getContents();
                    String cntrpartyFullName=rs.getCell(j++, i).getContents();
                    String uniformSocialCreditCode=rs.getCell(j++, i).getContents();
                    String needCreditFlag=rs.getCell(j++, i).getContents();
                    String isRelaTrade=rs.getCell(j++, i).getContents();
                    String cntrparyStatus=rs.getCell(j++, i).getContents();
                    String version=rs.getCell(j++, i).getContents();

                    System.out.println("cntrpartyType:"+cntrpartyType+" cntrpartyCode:"+cntrpartyCode+" cntrpartyName:"+cntrpartyName+cntrpartyFullName+uniformSocialCreditCode);
                    list.add(new Cntrparty(
                            cntrpartyType, cntrpartyCode, cntrpartyName,cntrpartyFullName, uniformSocialCreditCode,
                            needCreditFlag, isRelaTrade,cntrparyStatus,Integer.parseInt(version)));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;

    }

}
